//单实例数据库配置 database.html
app.controller('databaseCtrl', function ($scope, $http, $location) {
  //页面通用初始化
  pageInit('database');
  //初始化
  $http.get('/deploy/db/init').then(function (response) {
    if (response.status == 200) {
      var message = response.data;
      if (message.code == 0) {
        var data = message.data;
        $scope.bean = data;
      } else {
        $.showNotice(message.msg, "danger");
      }
    }
  }).catch(function (response) {
    $.showNotice(response.status + " error：" + response.data.message, "danger");
  });

  //测试数据库
  $scope.dbTest = function (bean) {
    $('#database .progress').slideDown(200);
    $('#database .alert-success').slideUp(200);
    $http.get('/deploy/db/test').then(function (response) {
      $('#database .progress').slideUp(200);
      if (response.status == 200) {
        var message = response.data;
        if (message.code == 0) {
          $('#database .alert-success').slideDown(200);
        } else {
          $.showNotice(message.msg, "danger");
        }
      }
    }).catch(function (response) {
      $.showNotice(response.status + " error：" + response.data.message, "danger");
    });
  };

  //配置数据库
  $scope.dbConfig = function (bean) {
    if ($scope.loadingNext) return;
    $scope.loadingNext = true;
    $http.get('/deploy/db/submit').then(function (response) {
      $scope.loadingNext = false;
      if (response.status == 200) {
        var message = response.data;
        if (message.code == 0) {
          $location.path('version');
        } else {
          $.showNotice(message.msg, "danger");
        }
      }
    }).catch(function (response) {
      $scope.loadingNext = false;
      $.showNotice(response.status + " error：" + response.data.message, "danger");
    });
  }

});